﻿@using FTBS.Models.Entities.Concert
@model PagedList.IPagedList<FTBS.Models.Entities.Concert.ReportTube>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
    ViewBag.Title = "Thống kê chi tiết";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    string usn = ViewBag.Supplier;
    int theaterId = ViewBag.TheaterId;
    DateTime fDate = ViewBag.FDate;
    DateTime tDate = ViewBag.TDate;
    DateTime firstFromDate = ViewBag.FirstFromDate;
    DateTime firstToDate = ViewBag.FirstToDate;
    string firstFromTime = firstFromDate.ToString("dd/MM/yyyy");
    string firstToTime = firstToDate.ToString("dd/MM/yyyy");
    //PagedList.IPagedList<ReportTube> TheaterBalance = ViewBag.TheaterBalance;

    bool isSortDes = ViewBag.IsSortDes;
    int totalNumBalance = ViewBag.totalNumBalance;
    double totalRevenue = ViewBag.TotalRevenue;
    double totalBalance = ViewBag.TotalBalance;
    int dataSize = ViewBag.DataSize;
    int pageTotalNumBalance = 0;
    double pageTotalRevenue = 0;
    double pageTotalTheaterBalance = 0;  
}
<style>
    .center {
        text-align: center;
    }

    .right {
        text-align: right;
    }
</style>
@* supplier's statistic and balancing*@
<div>
    @using (Html.BeginForm("SystemTheaterDaysDetail", "Report", FormMethod.Get))
    {
        if (Model.Count > 0)
        {
        <legend>CHI TIẾT THỐNG KÊ RẠP @Model[0].TheaterName.ToUpper()</legend>
        }
        else
        { <legend>CHI TIẾT THỐNG KÊ RẠP</legend>}  
        <input id="usn" type="text" name="usn" value="@usn" style="display:none"/>
        <input id="theaterId" type="text" name="theaterId" value="@theaterId" style="display:none"/>
        <input id="firstFromTime" type="text" name="firstFromTime" value="@firstFromTime" style="display:none"/>
        <input id="firstToTime" type="text" name="firstToTime" value="@firstToTime" style="display:none"/>
        <table class="table striped bordered" style="height: 35px">
            <tr>
                <th>Tìm kiếm:
                </th>
                <td>
                    @Html.TextBox("SearchString", ViewBag.CurrentFilter as string, new { style = "width: 200px; height: 34px;" })
                </td>
                <th>Từ ngày:
                </th>
                <td>
                    <div class="input-control text" data-role="datepicker"
                        data-date='@fDate'
                        data-format="dd/mm/yyyy"
                        data-position="bottom"
                        data-effect="slide"
                        data-other-days='1'>
                        <input type="text" id="fTime" name="fTime">
                        <button class="btn-date" type="button"></button>
                    </div>
                </td>
                <th>Đến ngày:
                </th>
                <td>
                    <div class="input-control text" data-role="datepicker"
                        data-date='@tDate'
                        data-format="dd/mm/yyyy"
                        data-position="bottom"
                        data-effect="slide"
                        data-other-days='1'>
                        <input type="text" id="tTime" name="tTime">
                        <button class="btn-date" type="button"></button>
                    </div>
                </td>
                <td>
                    <input class="inverse" type="submit" value="Tìm" style="height: 35px" />
                </td>
            </tr>
            @{
        bool isDateFalse = ViewBag.Alert;
        if (isDateFalse == true)
        {            
                <tr id="alert">
                    <td colspan="7" style="color: red; text-align: right; font-family: Arial; font-weight: 100;">Ngày trong mục "Từ ngày" không được lớn hơn ngày trong mục "Đến ngày"!
                    </td>
                </tr>
        }
            }
        </table>
    }
</div>
<table class="table striped bordered hovered" style="width: 100%">
    <tr>
        <th>@Html.ActionLink("Ngày", "SystemTheaterDaysDetail", new { usn, theaterId, fTime = fDate.ToString("dd/MM/yyyy"), tTime = tDate.ToString("dd/MM/yyyy"), sortOrder = "date_desc", isSortDescending = isSortDes, firstFromTime, firstToTime })
        </th>
        <th>@Html.ActionLink("Vé bán ra", "SystemTheaterDaysDetail", new { usn, theaterId, fTime = fDate.ToString("dd/MM/yyyy"), tTime = tDate.ToString("dd/MM/yyyy"), sortOrder = "sold_ticket_desc", isSortDescending = isSortDes, firstFromTime, firstToTime })
        </th>
        <th>@Html.ActionLink("Doanh thu", "SystemTheaterDaysDetail", new { usn, theaterId, fTime = fDate.ToString("dd/MM/yyyy"), tTime = tDate.ToString("dd/MM/yyyy"), sortOrder = "revenue_desc", isSortDescending = isSortDes, firstFromTime, firstToTime })
        </th>
        <th>@Html.ActionLink("Lợi nhuận ", "SystemTheaterDaysDetail", new { usn, theaterId, fTime = fDate.ToString("dd/MM/yyyy"), tTime = tDate.ToString("dd/MM/yyyy"), sortOrder = "balance_desc", isSortDescending = isSortDes, firstFromTime, firstToTime })
        </th>
    </tr>
    @foreach (var item in Model)
    {
        double pageBalance = 0;
        //caluculating balance in each tube
        pageBalance = item.Balance;
        pageTotalTheaterBalance = pageTotalTheaterBalance + pageBalance;
        pageTotalRevenue = pageTotalRevenue + item.TotalPrice;
        pageTotalNumBalance = pageTotalNumBalance + item.NumberOfSoldTicket;
        <tr>
            <td class="center">@item.ReportDate.ToString("dd/MM/yyyy")
            </td>
            <td class="right">@item.NumberOfSoldTicket
            </td>
            <td class="right">@item.TotalPrice.ToString("0,000")
            </td>
            <td class="right">@item.Balance.ToString("0,000")
            </td>
        </tr>
    }
    @if (dataSize > 9)
    {
        <tr>
            <th class="right">Tổng cộng trang @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber): 
            </th>
            <th class="right">@pageTotalNumBalance
            </th>
            <th class="right">@pageTotalRevenue.ToString("0,000")
            </th>
            <th class="right">@pageTotalTheaterBalance.ToString("0,000")
            </th>
        </tr>
    }
    @if (Model.Count > 0)
    {        
        <tr>
            <th class="right">Tổng cộng các trang: 
            </th>
            <th class="right">@totalNumBalance
            </th>
            <th class="right">@totalRevenue.ToString("0,000")
            </th>
            <th class="right">@totalBalance.ToString("0,000")
            </th>
        </tr>
    }else
    {        
        <tr>
            <th class="right">Tổng cộng các trang: 
            </th>
            <th class="right">0
            </th>
            <th class="right">0,000
            </th>
            <th class="right">0,000
            </th>
        </tr>
    }
</table>
<div style="float: right">
    <div style="float: right">
        Trang @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) của @Model.PageCount trang
    </div>
    <div>
        @Html.PagedListPager(Model, page => Url.Action("SystemTheaterDaysDetail",
            new { usn, theaterId, fTime = fDate.ToString("dd/MM/yyyy"), tTime = tDate.ToString("dd/MM/yyyy"), page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, firstFromTime, firstToTime }))
    </div>
</div>

<div>
    @*<a href="~/Report/Index">Quay lại</a>*@    
    <div>
        <button class="button danger" style="float: left">
            @Html.ActionLink("Quay Lại", "DateRangeAdminReportView", new { usn = "0", fDate = firstFromDate, tDate = firstToDate })
        </button>
    </div>
</div>